package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1052 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
            int sum = 0, n = customers.length, maxGain = 0, curGain = 0;
            for (int i = 0; i < n; i++) {
                sum += (1 - grumpy[i]) * customers[i];
            }

            for (int i = 0; i < minutes; i++) {
                curGain += grumpy[i] == 1 ? customers[i] : 0;
            }

            maxGain = curGain;
            for (int i = 1; i <= n - minutes; i++) {
                if (grumpy[i - 1] == 1) curGain -= customers[i - 1];
                if (grumpy[i + minutes - 1] == 1) curGain += customers[i + minutes - 1];
                maxGain = Math.max(maxGain, curGain);
            }

            return maxGain + sum;
        }
    }

    public void run() {
        System.out.println(new Solution().maxSatisfied(InputUtil.toIntegerArray("[1,0,1,2,1,1,7,5]"), InputUtil.toIntegerArray("[0,1,0,1,0,1,0,1]"), 3));
        System.out.println(new Solution().maxSatisfied(InputUtil.toIntegerArray("[1]"), InputUtil.toIntegerArray("[0]"), 1));
    }

    public static void main(String[] args) throws Exception {
        LC1052 an = new LC1052();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
